//
//  WUexperienceCell.m
//  Home
//
//  Created by 吴军虎吴军虎 on 16/5/5.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "WUexperienceCell.h"
#import "WSCustomLabel.h"

@interface WUexperienceCell(){
    NSInteger rowHeight;
}

@property (nonatomic, strong) UILabel *nameL;
@property (nonatomic, strong) WSCustomLabel *contentLabel;
@property (nonatomic, strong) UIImageView *lineV;
@property (nonatomic, strong) UIButton *showAll;

@end

@implementation WUexperienceCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView {
    
    [self createContentLabel];
    [self createLineV];
    [self createShowAll];
}

- (void)createContentLabel {
    
    
    _nameL = [UILabel new];
    _nameL.text = @"详细描述";
    _nameL.textColor = GH;
    _nameL.font = [UIFont fontWithName:TFont size:TEXTCONTENTFONT * AUTO_WIDTH];
    [self.contentView addSubview:_nameL];
    [_nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5 * AUTO_HEIGHT);
        make.height.mas_equalTo(70/2 * AUTO_HEIGHT);
        make.left.mas_equalTo(15 * AUTO_WIDTH);
        
    }];
    
    UIImageView *image = [UIImageView new];
    [self.contentView addSubview:image];
    image.image = [UIImage imageNamed:@"xueli"];
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_nameL).offset(4 *AUTO_HEIGHT);
        make.right.mas_equalTo(self).offset(- 15 * AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(25 * AUTO_WIDTH, 25* AUTO_HEIGHT));
        
        
    }];
    
    self.contentLabel = [[WSCustomLabel alloc] init];
    [self.contentView addSubview:_contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(46 * AUTO_WIDTH);
        make.left.mas_equalTo(@(15 * AUTO_WIDTH));
        make.right.mas_equalTo(@(-15 * AUTO_WIDTH));
        make.bottom.mas_equalTo(@(-40 * AUTO_WIDTH));
    }];
    NSString *labelText = @"我们需要装沙发都很困惑哈分行的说法是尽快发哈地方哈是减肥哈积分换积分哈大大舒服哈尽快发货的发生附近的合法数据库发哈减肥哈手机卡打发看哈接口或发髻哈发合法的开奖号发客服哈空间爱上的划分及案发哈哈就开始阿斯顿和福建按时缴费和骄傲是大好时机和福建按开始放假哎会发生修平层房子.........";
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
    self.contentLabel.attributedText = attributedString;

//
    CGSize maximumLabelSize=CGSizeMake(100, 100);
    
    CGSize size=[self sizeThatFits: maximumLabelSize];
    self.contentLabel.frame=CGRectMake(0, 0, size.width, size.height);
    
    self.contentLabel.textColor = [UIColor colorWithRed:0.52 green:0.51 blue:0.52 alpha:1];
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.lineBreakMode =  NSLineBreakByTruncatingTail;

    self.contentLabel.font = [UIFont systemFontOfSize:TEXTLABELFONT * TEXTWEIGHT];
}

- (void)createLineV {
    
    self.lineV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"虚线"]];
    [self.contentView addSubview:_lineV];
    [self.lineV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentLabel.mas_bottom).offset(5);
        make.left.mas_equalTo(@8);
        make.right.mas_equalTo(@-8);
        make.height.mas_equalTo(@1);
    }];
}

- (void)createShowAll {
    
    self.showAll = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_showAll];
    [self.showAll mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@(15 * AUTO_WIDTH));
        make.top.equalTo(self.lineV.mas_bottom);
        make.right.mas_equalTo(@(-15 * AUTO_WIDTH));
        make.bottom.mas_equalTo(@0);
    }];
    [self.showAll setTitle:@"显示全部" forState:UIControlStateNormal];
    [self.showAll setTitleColor:GH forState:UIControlStateNormal];
    self.showAll.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.showAll.titleLabel.font = [UIFont systemFontOfSize:LOGINFONT *TEXTWEIGHT];
    [self.showAll addTarget:self action:@selector(showAllAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)showAllAction:(UIButton *)btn {
    
    btn.selected = !btn.isSelected;
    [self.delegate changeShowState:!btn.isSelected];
    if (btn.isSelected) {
        [self.showAll setTitle:@"收起" forState:UIControlStateNormal];
    }
    else {
        [self.showAll setTitle:@"显示全部" forState:UIControlStateNormal];
    }
}



@end
